package com.leetcode.partition21;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/2/2 9:57
 */
public class LC2000反转单词前缀 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        writer.write(reversePrefix(ss[0], ss[1].charAt(0)));
        writer.flush();
    }

    public static String reversePrefix(String word, char ch) {
        int right = 0;
        for (int i = 0; i < word.length(); i++) {
            if (word.charAt(i) == ch) {
                right = i;
                break;
            }
        }
        right++;
        char[] res = word.toCharArray();
        for (int i = 0; i < right / 2; i++) {
            char c = res[i];
            res[i] = res[right - i - 1];
            res[right - i - 1] = c;
        }
        return new String(res);
    }
}
